/*     */ package com.zimbra.qa.unittest;
/*     */ 
/*     */ import com.zimbra.common.account.Key.AccountBy;
/*     */ import com.zimbra.common.account.Key.DistributionListBy;
/*     */ import com.zimbra.common.account.Key.DomainBy;
/*     */ import com.zimbra.common.account.ZAttrProvisioning.GalMode;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.DistributionList;
/*     */ import com.zimbra.cs.account.Domain;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.ldap.LdapUtil;
/*     */ import com.zimbra.cs.mailbox.calendar.ZAttendee;
/*     */ import com.zimbra.cs.service.mail.CalendarUtils;
/*     */ import com.zimbra.qa.unittest.prov.soap.GalTestUtil;
/*     */ import java.util.ArrayList;
/*     */ import java.util.HashMap;
/*     */ import java.util.HashSet;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.Set;
/*     */ import junit.framework.TestCase;
/*     */ import org.junit.AfterClass;
/*     */ import org.junit.BeforeClass;
/*     */ import org.junit.Test;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class TestCalAttendeesDiff
/*     */   extends TestCase
/*     */ {
/*     */   private static final String ZIMBRA_DOMAIN = "zimbra.galgrouptest";
/*  57 */   private static final String ZIMBRA_GROUP = TestUtil.getAddress("zimbra-group", "zimbra.galgrouptest");
/*     */   
/*     */   private static final String EXTERNAL_DOMAIN = "external.galgrouptest";
/*  60 */   private static final String EXTERNAL_GROUP = TestUtil.getAddress("external-group", "external.galgrouptest");
/*     */   
/*  62 */   private static final String REQUESTER = TestUtil.getAddress("requester", "zimbra.galgrouptest");
/*  63 */   private static final String USER_L1 = TestUtil.getAddress("user-L1", "zimbra.galgrouptest");
/*  64 */   private static final String USER_L2 = TestUtil.getAddress("user-L2", "zimbra.galgrouptest");
/*  65 */   private static final String USER_L2_ALIAS = TestUtil.getAddress("user-L2-alias", "zimbra.galgrouptest");
/*  66 */   private static final String USER_L3 = TestUtil.getAddress("user-L3", "zimbra.galgrouptest");
/*  67 */   private static final String USER_R1 = TestUtil.getAddress("user-R1", "zimbra.galgrouptest");
/*  68 */   private static final String USER_R2 = TestUtil.getAddress("user-R2-ext", "external.galgrouptest");
/*  69 */   private static final String USER_R3 = TestUtil.getAddress("user-R3", "zimbra.galgrouptest");
/*     */   
/*     */ 
/*     */ 
/*  73 */   private static boolean initialized = false;
/*  74 */   private static boolean allDone = false;
/*     */   
/*     */   public void setUp() throws Exception {
/*  77 */     if (!initialized) {
/*  78 */       init();
/*  79 */       initialized = true;
/*     */     }
/*     */   }
/*     */   
/*     */   public void tearDown() throws Exception {
/*  84 */     if (allDone) {
/*  85 */       cleanup();
/*  86 */       initialized = false;
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   @BeforeClass
/*     */   public static void init()
/*     */     throws Exception
/*     */   {
/*  96 */     Provisioning prov = Provisioning.getInstance();
/*     */     
/*     */ 
/*  99 */     if (prov.get(Key.DomainBy.name, "zimbra.galgrouptest") == null) {
/* 100 */       ZimbraLog.test.info("Creating domain zimbra.galgrouptest");
/* 101 */       Domain domain = prov.createDomain("zimbra.galgrouptest", new HashMap());
/*     */       
/*     */ 
/* 104 */       Map<String, Object> attrs = new HashMap();
/* 105 */       domain.setGalMode(ZAttrProvisioning.GalMode.both, attrs);
/* 106 */       domain.addGalLdapURL("ldap://localhost:389", attrs);
/* 107 */       domain.setGalLdapBindDn("cn=config", attrs);
/* 108 */       domain.setGalLdapBindPassword("zimbra");
/* 109 */       domain.setGalLdapSearchBase(LdapUtil.domainToDN("external.galgrouptest"));
/* 110 */       domain.setGalAutoCompleteLdapFilter("zimbraAccountAutoComplete");
/* 111 */       domain.setGalLdapFilter("zimbraAccounts");
/*     */       
/* 113 */       prov.modifyAttrs(domain, attrs);
/*     */     }
/*     */     
/*     */ 
/* 117 */     if (prov.get(Key.DomainBy.name, "external.galgrouptest") == null) {
/* 118 */       ZimbraLog.test.info("Creating domain external.galgrouptest");
/* 119 */       prov.createDomain("external.galgrouptest", new HashMap());
/*     */     }
/*     */     
/*     */ 
/* 123 */     String[] users = { REQUESTER, USER_L1, USER_L2, USER_L3, USER_R1, USER_R2, USER_R3 };
/* 124 */     for (String userAddr : users) {
/* 125 */       if (prov.get(Key.AccountBy.name, userAddr) == null) {
/* 126 */         prov.createAccount(userAddr, "test123", null);
/*     */       }
/*     */     }
/*     */     
/* 130 */     Account acctL2 = prov.get(Key.AccountBy.name, USER_L2);
/* 131 */     acctL2.addAlias(USER_L2_ALIAS);
/*     */     
/*     */ 
/* 134 */     DistributionList group = prov.get(Key.DistributionListBy.name, ZIMBRA_GROUP);
/* 135 */     if (group == null) {
/* 136 */       group = prov.createDistributionList(ZIMBRA_GROUP, new HashMap());
/* 137 */       prov.addMembers(group, new String[] { USER_L1, USER_L2_ALIAS, USER_R1 });
/*     */     }
/*     */     
/*     */ 
/* 141 */     DistributionList extGroup = prov.get(Key.DistributionListBy.name, EXTERNAL_GROUP);
/* 142 */     if (extGroup == null) {
/* 143 */       extGroup = prov.createDistributionList(EXTERNAL_GROUP, new HashMap());
/* 144 */       prov.addMembers(extGroup, new String[] { USER_R2 });
/*     */     }
/*     */   }
/*     */   
/*     */   @AfterClass
/*     */   public static void cleanup() throws Exception {
/* 150 */     Provisioning prov = Provisioning.getInstance();
/*     */     
/* 152 */     GalTestUtil.disableGalSyncAccount(prov, "zimbra.galgrouptest");
/*     */     
/*     */ 
/* 155 */     String[] users = { REQUESTER, USER_L1, USER_L2, USER_L3, USER_R1, USER_R2, USER_R3 };
/* 156 */     for (String userAddr : users) {
/* 157 */       Account userAcct = prov.get(Key.AccountBy.name, userAddr);
/* 158 */       if (userAcct != null) {
/* 159 */         prov.deleteAccount(userAcct.getId());
/*     */       }
/*     */     }
/*     */     
/*     */ 
/* 164 */     DistributionList extGroup = prov.get(Key.DistributionListBy.name, EXTERNAL_GROUP);
/* 165 */     if (extGroup != null) {
/* 166 */       prov.deleteDistributionList(extGroup.getId());
/*     */     }
/*     */     
/* 169 */     Domain extDomain = prov.get(Key.DomainBy.name, "external.galgrouptest");
/* 170 */     if (extDomain != null) {
/* 171 */       ZimbraLog.test.info("Deleting domain external.galgrouptest");
/* 172 */       prov.deleteDomain(extDomain.getId());
/*     */     }
/*     */     
/*     */ 
/* 176 */     DistributionList group = prov.get(Key.DistributionListBy.name, ZIMBRA_GROUP);
/* 177 */     if (group != null) {
/* 178 */       prov.deleteDistributionList(group.getId());
/*     */     }
/*     */     
/* 181 */     Domain domain = prov.get(Key.DomainBy.name, "zimbra.galgrouptest");
/* 182 */     if (domain != null) {
/* 183 */       ZimbraLog.test.info("Deleting domain zimbra.galgrouptest");
/* 184 */       prov.deleteDomain(domain.getId());
/*     */     }
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void testAttendeesDiff() throws Exception {
/* 190 */     Provisioning prov = Provisioning.getInstance();
/* 191 */     Account requester = prov.get(Key.AccountBy.name, REQUESTER);
/*     */     
/* 193 */     List<ZAttendee> oldList = new ArrayList();
/* 194 */     oldList.add(new ZAttendee(ZIMBRA_GROUP));
/* 195 */     oldList.add(new ZAttendee(EXTERNAL_GROUP));
/* 196 */     oldList.add(new ZAttendee(USER_L1));
/* 197 */     oldList.add(new ZAttendee(USER_L2));
/* 198 */     oldList.add(new ZAttendee(USER_L3));
/* 199 */     oldList.add(new ZAttendee(USER_R1));
/* 200 */     oldList.add(new ZAttendee(USER_R2));
/* 201 */     oldList.add(new ZAttendee(USER_R3));
/*     */     
/*     */ 
/* 204 */     List<ZAttendee> newList = new ArrayList();
/* 205 */     newList.add(new ZAttendee(ZIMBRA_GROUP));
/* 206 */     newList.add(new ZAttendee(EXTERNAL_GROUP));
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 211 */     Set<String> diff = toAddressSet(CalendarUtils.getRemovedAttendees(oldList, newList, true, requester));
/* 212 */     assertTrue(USER_L3 + " was removed", diff.contains(USER_L3));
/* 213 */     assertTrue(USER_R3 + " was removed", diff.contains(USER_R3));
/* 214 */     assertEquals("number of attendees removed", 2, diff.size());
/*     */     
/*     */ 
/* 217 */     diff = toAddressSet(CalendarUtils.getRemovedAttendees(oldList, newList, false, requester));
/* 218 */     assertTrue(USER_L1 + " was removed", diff.contains(USER_L1));
/* 219 */     assertTrue(USER_L2 + " was removed", diff.contains(USER_L2));
/* 220 */     assertTrue(USER_L3 + " was removed", diff.contains(USER_L3));
/* 221 */     assertTrue(USER_R1 + " was removed", diff.contains(USER_R1));
/* 222 */     assertTrue(USER_R2 + " was removed", diff.contains(USER_R2));
/* 223 */     assertTrue(USER_R3 + " was removed", diff.contains(USER_R3));
/* 224 */     assertEquals("number of attendees removed", 6, diff.size());
/*     */   }
/*     */   
/*     */   private Set<String> toAddressSet(List<ZAttendee> attList) {
/* 228 */     Set<String> set = new HashSet();
/* 229 */     for (ZAttendee att : attList) {
/* 230 */       set.add(att.getAddress());
/*     */     }
/* 232 */     return set;
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void testLast() throws Exception
/*     */   {
/* 238 */     allDone = true;
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/TestCalAttendeesDiff.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */